<template>
  <card>
    <div class="search-con search-con-top">
      <Button @click="edit(0,0)" class="search-btn" type="primary">
        <Icon type="search"/>&nbsp;添加
      </Button>
    </div>
    <Table :columns="columns1" :data="data1"></Table>
  </card>
</template>

<script>
import Bus from '@/libs/bus.js'
import { getAttributeList } from "@/api/data";
export default {
  name:'attributesaaa',
  data() {
    return {
      columns1: [
        {
          title: "编号",
          key: "attrID"
        },
        {
          title: "名称",
          key: "name"
        },
        {
          title: "操作",
          key: "action",
          width: 150,
          align: "center",
          render: (h, params) => {
            return h("div", [
              h(
                "Button",
                {
                  props: {
                    type: "primary",
                    size: "small"
                  },
                  style: {
                    marginRight: "5px"
                  },
                  on: {
                    click: () => {
                      this.edit(params.index, params.row.attrID);
                    }
                  }
                },
                "编辑"
              ),
              h(
                "Button",
                {
                  props: {
                    type: "error",
                    size: "small"
                  },
                  on: {
                    click: () => {
                      this.delData(params.index, params.row.attrID);
                    }
                  }
                },
                "删除"
              )
            ]);
          }
        }
      ],
      data1: [],
      searchModel: {
        userId: 0,
        sellerId: 0,
        categoryID: this.$route.query.id
      }
    };
  },
  methods: {
    getData() {
      //获取数据
      getAttributeList(this.searchModel).then(res => {
        this.data1 = res.data.data;
      });
    },
    edit(index, attrID) {
      var cateid=this.$route.query.id;
      var id=attrID;
      const route = {
        name: 'attributes_edit',
        query: {
          id,cateid
        },
        meta: {
          title: `编辑产品规格-${id}`
        }
      }
      this.$router.push(route)
    },
  },
  mounted() {
    debugger;
    this.getData(); //初始化数据
    let self = this
    Bus.$on('attributes_edit', (e) => {
      self.message = e
　　　　//console.log(`传来的数据是：${e}`)
      this.getData();
    })
  }
};
</script>
